package cn.iocoder.yudao.module.trade.dal.mysql.order;

import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderItemDO;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import org.apache.ibatis.annotations.Mapper;

import java.util.Collection;
import java.util.List;

/**
 * 交易订单项映射器
 *
 * @author huangweidong
 * @date 2023/05/09
 */
@Mapper
public interface TradeOrderItemMapper extends BaseMapperX<TradeOrderItemDO> {

    /**
     * 更新售后状态
     *
     * @param id                 id
     * @param oldAfterSaleStatus 老售后状态
     * @param newAfterSaleStatus 新售后状态
     * @return int
     */
    default int updateAfterSaleStatus(Long id, Integer oldAfterSaleStatus, Integer newAfterSaleStatus) {
        return update(new TradeOrderItemDO().setAfterSaleStatus(newAfterSaleStatus),
                new LambdaUpdateWrapper<>(new TradeOrderItemDO().setId(id).setAfterSaleStatus(oldAfterSaleStatus)));
    }

    /**
     * 查询列表通过订单id
     *
     * @param orderId 订单id
     * @return {@code List<TradeOrderItemDO>}
     */
    default List<TradeOrderItemDO> selectListByOrderId(Long orderId) {
        return selectList(TradeOrderItemDO::getOrderId, orderId);
    }

    /**
     * 查询列表通过订单id
     *
     * @param orderIds 订单id
     * @return {@code List<TradeOrderItemDO>}
     */
    default List<TradeOrderItemDO> selectListByOrderId(Collection<Long> orderIds) {
        return selectList(TradeOrderItemDO::getOrderId, orderIds);
    }

}
